package com.hospital.datasource.config;

import com.alibaba.druid.util.StringUtils;
import lombok.Data;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Map;

@AutoConfiguration
@Data
@ConfigurationProperties(prefix = "tenantcode")
public class TenantCodeConfig {
    private String ignoreUrl;
    private Map<String,String> mapping;

    public String getTenantIdByTenantCode(String tenantCode){
        if(StringUtils.isEmpty(tenantCode)){
            return null;
        }
        return mapping.get(tenantCode);
    }

    public String getTenantCodeByTenantId(String tenantId){
        if(tenantId==null){
            return null;
        }
        return mapping.entrySet().stream().filter(c->c.getValue().equals(tenantId)).map(c->c.getKey()).findFirst().orElse(null);
    }
}
